package cn.gnp.framework.eeamis.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.gnp.framework.persist.Constants;
import cn.gnp.framework.persist.dao.hibernate.BaseHibernateDao;
import cn.gnp.framework.eeamis.dao.goods.IGoodsDao;
import cn.gnp.framework.eeamis.model.goods.GoodsModel;

@Repository
public class GoodsHibernateDao extends BaseHibernateDao<GoodsModel, Integer> implements IGoodsDao {
   
    public void delete(Integer id) {
        GoodsModel goods = get(id);
        goods.setDeleted(true);
        update(goods);
    }
    
    protected String getCountAllHql() {
        return super.getCountAllHql() + " where deleted=false";
    }
    
       
    protected String getListAllHql() {
        return super.getListAllHql() + " where deleted=false";
    }

    
    public int countAllPublished() {
        String hql = getCountAllHql() + " and published=true";
        Number result = unique(hql);
        return result.intValue();
    }
    
    
    public List<GoodsModel> listAllPublished(int pn) {
        String hql = getListAllHql() + " and published=true";
        return list(hql, pn, Constants.DEFAULT_PAGE_SIZE);
    }


}
